package com.inet.app.framework.network;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class NetworkStateReceiver extends BroadcastReceiver {
	
	private boolean isWifiEnabled = false;
	private boolean is3gEnabled = false;
	
	private static NetworkStateListener networkStateListener;
	
	@Override
	public void onReceive(Context context, Intent intent) {
		isWifiEnabled = NetworkUtil.getInstance(context).isConnectWifi();
		is3gEnabled   = NetworkUtil.getInstance(context).isConnect3G();
		
		if(null == networkStateListener) {
			return;
		}
		
		if(isWifiEnabled && !is3gEnabled) {
			networkStateListener.enableWifi();
			networkStateListener.disable3g();
		}
		else if(!isWifiEnabled && is3gEnabled) {	
			networkStateListener.enable3g();
			networkStateListener.disableWifi();
		}
		else if(isWifiEnabled && is3gEnabled) {
			networkStateListener.enableAll();
		}
		else {
			networkStateListener.disableAll();
		}
	}
	
	public static void setNetworkListener(NetworkStateListener listener) {
		networkStateListener = listener;
	}
	
	public static void removeNetworkListener() {
		networkStateListener = null;
	}

}
